import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot, ActivatedRoute, Router } from '@angular/router';
import { ZoneService, ZoneModel, Zone } from './zone.service';

@Injectable({
	providedIn: 'root',
})
export class DetailsService implements Resolve<Zone> {
	constructor(private zoneService: ZoneService, private router: Router) {}

	async resolve(route: ActivatedRouteSnapshot) {
    const id = Number(route.queryParamMap.get('id'));
    try {
      const zone = await this.zoneService.get(id);
      return zone;
    } catch (error) {
      this.router.navigateByUrl('/');
    }
	}
}
